package com.example.controller.pc;


import com.example.common.result.Result;
import com.example.entity.dto.pc.ListDto;
import com.example.entity.vo.pc.*;
import com.example.entity.ymlConfig.YmlConfig;
import com.example.mapper.hzViewSync.HzViewSyncMapper;
import com.example.mapper.pc.WLPHZBMapper;
import com.example.service.pc.WLPHZBService;
import com.example.untils.StringUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/api/WLPHZB")
@Api(tags = "物料平衡总表")
public class WLPHZBController {

    @Autowired
    private WLPHZBService service;

    @Resource
    private WLPHZBMapper mapper;


    @ApiOperation("列表")
    @PostMapping("list")
    public Result<ListVo> list(@RequestBody ListDto dto) {
        if(dto.getRefreshDB()) {
            if("hz".equals(YmlConfig.getActive()) || "hznw".equals(YmlConfig.getActive())) {
                service.refreshWLXQhzView();
            }else{
                service.refreshWLXQ();
            }
        }
        return Result.success(service.list(dto));
    }

    @ApiOperation("查看明细 [总需求]")
    @GetMapping("viewDetailsOnNeed/{productId}")
    public Result<List<ZXQneed>> viewDetailsOnNeed(@PathVariable String productId) {
        if(StringUtils.isEmpty(productId)) {
            return Result.error("品号不能为空");
        }
        List<ZXQneed> list = mapper.need(productId);
        return Result.success(list);
    }

    @ApiOperation("查看明细 [总生产量]")
    @GetMapping("viewDetails/{productId}")
    public Result<List<GongDan>> viewDetails(@PathVariable String productId) {
        if(StringUtils.isEmpty(productId)) {
            return Result.error("品号不能为空");
        }
        List<GongDan> list = mapper.MOCTA(productId);
        return Result.success(list);
    }

    @ApiOperation("查看明细 [日期单元格上]")
    @GetMapping("viewDetailsOnDate/{productId}/{date}")
    public Result<List<XQLVo>> viewDetailsOnDate(@PathVariable String productId, @PathVariable String date) {
        if(StringUtils.isEmpty(productId) || StringUtils.isEmpty(date)) {
            return Result.error("品号，日期不能为空");
        }
        List<XQLVo> list = mapper.XQL(productId, date);
        return Result.success(list);
    }

    @ApiOperation("查看明细 [已购未回量]")
    @GetMapping("viewDetailsOnPurchasedNoReturnNums/{productId}")
    public Result<List<YGWHL>> viewDetailsOnPurchasedNoReturnNums(@PathVariable String productId) {
        if(StringUtils.isEmpty(productId)) {
            return Result.error("品号不能为空");
        }
        List<YGWHL> list = mapper.purchasedNoReturnNums(productId);
        return Result.success(list);
    }

    @ApiOperation("查看明细 [总库存]")
    @GetMapping("viewDetailsOnTotalInventoryNums/{productId}")
    public Result<List<ZKC>> viewDetailsOnTotalInventoryNums(@PathVariable String productId) {
        if(StringUtils.isEmpty(productId)) {
            return Result.error("品号不能为空");
        }
        List<ZKC> list = null;
        if("hz".equals(YmlConfig.getActive()) || "hznw".equals(YmlConfig.getActive())) {
            list = mapper.totalInventoryNumsHzView(productId);
        }else{
            list = mapper.totalInventoryNums(productId);
        }
        return Result.success(list);
    }

    @ApiOperation("右击，查看替代料具体信息")
    @GetMapping("viewReplaceItem/{productId}")
    public Result<List<ViewReplaceItemVo>> viewReplaceItem(@PathVariable String productId) {
        if(StringUtils.isEmpty(productId)) {
            return Result.error("品号不能为空");
        }
        List<ViewReplaceItemVo> list = null;
        if("hz".equals(YmlConfig.getActive()) || "hznw".equals(YmlConfig.getActive())) {
            List<String> strings = mapper.replaceItem(productId);
            if(!strings.isEmpty()) {
                list = mapper.viewReplaceItemVo(strings);
            }
        }
        return Result.success(list);
    }

}
